﻿@{
    ViewBag.Title = "Member";
}
@section scripts
{  
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script> 
    <script src="@Url.Content("~/Scripts/shared/shown.js")" type="text/javascript"></script>   
}
   <body>
     <div class="mini-splitter" style="width:100%;height:100%;">
    <div size="200" showcollapseButton="true">
        <div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;">                
            <a class="mini-button" iconcls="icon-new" plain="true">积分规则列表</a>
            
        </div>
        <div class="mini-fit">
           <ul id="tree1" class="mini-tree" style="width:100%;" expandOnLoad="0"
              textField="FName" idField="FItemID" parentField="FParentID" showTreeIcon="true" resultAsTree="false">        
           </ul>
        </div>
    </div>
        <div showCollapseButton="true">
          <div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;">
          <table style="width:100%;">
            <tr>
            <td style="width:100%;">
                <a class="mini-button" id="save" iconCls="icon-edit" onclick="SaveData" plain="true" visible="@ViewBag.save">保存</a>
                <span class="separator"></span>
                <a class="mini-button" iconCls="icon-close" onclick="CloseWindow" plain="true">关闭</a>
            </td>
            </tr>
        </table>                
        </div>
        <div class="mini-fit" >
            <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" 
                borderStyle="border:0;"pageSize="15"showPager = "false" showPageSize="false" showPageIndex="false" 
                url="GetIntegralRuleList" allowCellSelect="true" allowCellEdit="true"showColumnsMenu="true"fitColumns="false"  
                oncellcommitedit="onCellCommitEdit">
                <div property="columns">
                   <div type="indexcolumn" ></div>
                   <div field="FName" name="FName" width="280" headerAlign="center" allowSort="true">名称</div>  
                   <div type="checkboxcolumn" field="FRuleFlag" name="FRuleFlag" trueValue="1" falseValue="0" width="70" headerAlign="center">是否积分</div>
                   <div field="FNubValue" name="FNubValue" width="150" numberFormat="n4" headerAlign="center" align="right">积分(消费多少元积1分)
                        <input property="editor" class="mini-spinner" minValue="0" maxValue="99999999" changeOnMousewheel ="false" showbutton="false" increment ="0"/>
                   </div>
                   <div field="FRemark" name="FRemark" width="100" headerAlign="center" allowSort="true">备注
                        <input property="editor" class="mini-textbox" style="width:100%;"/> 
                   </div>  
                </div>  
            </div>
         </div>  
        </div>
    </div>     
      <script type="text/javascript">
          mini.parse();
          var tree = mini.get("tree1");
          var grid = mini.get("datagrid1");

          function FormShown() {
              LoadListTree();
              tree.on("nodeselect", function (e) {
                  LoadListData();
              });
              LoadListData();
          }

          //加载分类树
          function LoadListTree() {
              var sSystemAppID = parent.window.getSystemAppID();
              var tree = mini.get("tree1");
              $.post('GetIntegralRuletype', { mjson: sSystemAppID }, function (data) {
                  tree.loadList(mini.decode(data));
                  tree.select(0);
              });
          }

          //加载资料列表
          function LoadListData() {
              var grid = mini.get("datagrid1");//==
              var sSystemAppID = parent.window.getSystemAppID();
              var mload = tree.getData();
              if (mload.length > 0) {
                  var node = tree.getSelectedNode();
                  var classid = node.FItemID;

                  switch (classid) {
                      case -1:   
                          grid.setData(null);
                          break;
                      case 2:
                          grid.hideColumn(grid.getColumn(3));
                          grid.updateColumn("FRuleFlag", { header: "是否积分" });
                          grid.updateColumn("FNubValue", { header: "积分(消费多少元积1分)" });
                          break;
                      case 0:
                      case 3:
                          grid.showColumn(grid.getColumn(3));
                          grid.updateColumn("FRuleFlag", { header: "是否积分" });
                          grid.updateColumn("FNubValue", { header: "积分(消费多少元积1分)" });
                          break;
                      case 10:
                          grid.updateColumn("FRuleFlag", { header: "是否抵现" });
                          grid.updateColumn("FNubValue", { header: "抵现(扣减多少积分抵1元)" });
                          grid.showColumn(grid.getColumn(3));
                          break;
                      case 11:
                          grid.updateColumn("FRuleFlag", { header: "是否积分" });
                          grid.updateColumn("FNubValue", { header: "关联卡积分比例" });
                          grid.showColumn(grid.getColumn(3));
                          break;
                  }

                  var json = "[{";
                  json = json + "'FSystemAppID':" + "'" + sSystemAppID + "',";
                  json = json + "'FClassID':" + "'" + classid + "',";
                  json = json + "'FNumber':" + "''";
                  json = json + "}]";
                  grid.load({ mjson: json });
                  setState(classid);
              }
          }

          function setState(flag) {
              mini.get("save").setEnabled(false);
          }

          function SaveData() {
              var s = grid.getData();
              var mData = mini.encode(s);
              $.post("../Member/SaveIntegralRule", { json: mData, mSystemAppID: parent.window.getSystemAppID() }, function (data) {
                  var ret = mini.decode(data);
                  if (ret.status == 1) {
                      grid.unmask();
                      mini.get("save").setEnabled(false);
                      mini.showTips({ content: ret.msg, state: "success", x: "center", y: "top", timeout: 3000 });
                  }
                  else {
                      mini.alert("异常:" + ret.error);
                  }
              });              
          }

          function onCellCommitEdit(e) {
              mini.get("save").setEnabled(true); //编辑后保存按钮可用
          }

     </script>
</body>